package com.lk.springboot.config;

import com.alibaba.fastjson.JSON;
import com.lk.springboot.bean.JsonResult;
import com.lk.springboot.bean.ResultCode;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommonErrorController implements ErrorController {

    private final String ERROR_PATH = "/error";

    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }

    @RequestMapping(value = ERROR_PATH)
    public String handleError(){
        JsonResult result = new JsonResult(ResultCode.UNEXPECTED_ERROR);
        result.setData("路径或者参数有误，请重新输入");
        return JSON.toJSONString(result);
    }
}
